﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class TinTuc : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string type = Request.QueryString["type"];
        string _id = Request.QueryString["id"];// de lay thong tin 1 tin
        type = TTQT.TTQT_Code.TTQTCommon.isNull(type, "");
        Response.ContentType = "application/json";
        if(string.IsNullOrEmpty(type))
        {
            Response.Write("");
        }
        //Lay toan bo tin tuc
        if(type.Equals("getall"))
        {
            Response.Write(new TinTucDAO().tinTuc_GetByNhomId_Json("-1", "-1"));
        }
        //Lay theo nhom
        //but/ajax/TinTuc.aspx?type=news&catid=2
        if (type.Equals("news"))
        {
            string catid = Request.QueryString["catid"];
            Response.Write(new TinTucDAO().tinTuc_GetByNhomId_Json(catid, "-1"));
        }
        //Lấy tốp num các tin theo nhóm
        //but/ajax/TinTuc.aspx?type=topnews&num=12&cateid=2
        if (type.Equals("topnews"))
        {
            string num = Request.QueryString["num"];
            string newsid = Request.QueryString["cateid"];
            Response.Write(new TinTucDAO().news_GetTopByCategory_Json(num, newsid));
        }
        //Lấy tốp num các tin có cùng mục sau tin hiện tại - Tin đã đưa
        //but/ajax/TinTuc.aspx?type=tindadua&num=9999&newsid=1
        if (type.Equals("tindadua"))
        {
            string num = Request.QueryString["num"];
            string newsid = Request.QueryString["newsid"];
            Response.Write(new TinTucDAO().News_getOtherByNewsId_Json(num, newsid));
        }
        ////Lay cac tin tuc hot
        //if (type.Equals("newshot"))
        //{
        //    string soluong = Request.QueryString["soluong"];
        //    Response.Write(new TinTucDAO().sanPHam_GetTopHot_Json(soluong));
        //}
        ////lay cac tin tuc ban chay
        //if (type.Equals("spbanchay"))
        //{
        //    string soluong = Request.QueryString["soluong"];
        //    Response.Write(new SanPhamDAO().sanPHam_GetTopBanChay_Json(soluong));
        //}
        ////Lay cac tin tuc giam gia
        //if (type.Equals("giamgia"))
        //{
        //    string soluong = Request.QueryString["soluong"];
        //    Response.Write(new SanPhamDAO().sanPHam_GetTopCoGiamGia_Json(soluong));
        //}
        //lay danh muc nhom tin tuc
        //but/ajax/TinTuc.aspx?type=menu
        if(type.Equals("menu"))
        {
            Response.Write(new QuanTriDAO().tinTuc_nhom_getall_Json());
        }
        //Lay thong tin chi tiet 1 tin tuc
        //but/ajax/TinTuc.aspx?type=getbyid&id=1
        if(type.Equals("getbyid"))
        {
            Response.Write(new TinTucDAO().getById_json(_id));
        }
    }
}
